﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Windows;

namespace TV_Organizer
{
    public class Log
    {
        public Log(DateTime time, string message)
        {
            this.Time = time;
            this.Message = message;
        }

        public string Message { get; private set; }
        public DateTime Time { get; private set; }
        public object Category { get; set; }
    }

    public static class LogsManager
    {
        static LogsManager()
        {
            LogsManager.Logs = new ObservableCollection<Log>();
        }

        public static ObservableCollection<Log> Logs { get; private set; }

        public static void Log(object sender, string message, params object[] stringFormatArgs)
        {
            Log(sender, string.Format(message, stringFormatArgs));
        }

        public static void Log(object sender, string message)
        {
            var log=  new Log(DateTime.Now, message)
            {
                Category = sender.GetType().Name,
            };
            Debug.WriteLine(string.Format("{0}: {1}", log.Time, log.Message), log.Category);

            Application.Current.Dispatcher.BeginInvoke(new System.Action<Log>((l) => LogsManager.Logs.Add(l)), System.Windows.Threading.DispatcherPriority.Background, log);

        }
    }
}
